<!doctype html><html lang dir=ltr><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>【第8周程序】程序设计方法学 | Python | Hui.Ke - Blog</title><meta name=generator content="Hugo Eureka 0.9.3"><link rel=stylesheet href=https://b.hui.ke/css/eureka.min.9cec6350e37e534b0338fa9a085bf06855de3b0f2dcf857e792e5e97b07ea905d4d5513db554cbc26a9c3da622bae92d.css><script defer src=https://b.hui.ke/js/eureka.min.fa9a6bf6d7a50bb635b4cca7d2ba5cf3dfb095ae3798773f1328f7950028b48c17d06276594e1b5f244a25a6c969a705.js></script>
<link rel=preconnect href=https://fonts.googleapis.com><link rel=preconnect href=https://fonts.gstatic.com crossorigin><link rel=preload href="https://fonts.googleapis.com/css2?family=Lora:wght@400;600;700&family=Noto+Serif+SC:wght@400;600;700&display=swap" as=style onload='this.onload=null,this.rel="stylesheet"'><link rel=stylesheet href=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/styles/vs.min.css media=print onload='this.media="all",this.onload=null' crossorigin><script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/bash.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/ini.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/json.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/php.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/python.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/shell.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/sql.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/x86asm.min.js crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/xml.min.js crossorigin></script>
<link rel=stylesheet href=https://b.hui.ke/css/highlightjs.min.2958991528e43eb6fc9b8c4f2b8e052f79c4010718e1d1e888a777620e9ee63021c2c57ec7417a3108019bb8c41943e6.css media=print onload='this.media="all",this.onload=null'><script defer type=text/javascript src=https://lib.baomitu.com/font-awesome/6.1.1/js/all.min.js></script>
<link rel=stylesheet href=https://cdn.jsdelivr.net/npm/katex@0.15.2/dist/katex.min.css integrity=sha384-MlJdn/WNKDGXveldHDdyRP1R4CTHr3FeuDNfhsLPYrq2t0UBkUdK2jyTnXPEK1NQ media=print onload='this.media="all",this.onload=null' crossorigin><script defer src=https://cdn.jsdelivr.net/npm/katex@0.15.2/dist/katex.min.js integrity=sha384-VQ8d8WVFw0yHhCk5E8I86oOhv48xLpnDZx5T9GogA/Y84DcCKWXDmSDfn13bzFZY crossorigin></script>
<script defer src=https://cdn.jsdelivr.net/npm/katex@0.15.2/dist/contrib/auto-render.min.js integrity=sha384-+XBljXPPiv+OzfbB3cVmLHf4hdUFHlWNZN5spNQ7rmHTXpd7WvJum6fIACpNNfIR crossorigin></script>
<script>document.addEventListener("DOMContentLoaded",function(){renderMathInElement(document.body,{delimiters:[{left:"$$",right:"$$",display:!0},{left:"$",right:"$",display:!1},{left:"\\(",right:"\\)",display:!1},{left:"\\[",right:"\\]",display:!0}]})})</script><script defer src=https://cdn.jsdelivr.net/npm/mermaid@8.14.0/dist/mermaid.min.js integrity=sha384-atOyb0FxAgN9LyAc6PEf9BjgwLISyansgdH8/VXQH8p2o5vfrRgmGIJ2Sg22L0A0 crossorigin></script>
<link rel=icon type=image/png sizes=32x32 href=https://b.hui.ke/icon_hub7ca0b5404c6d576559b2bd22c64b0e5_2009_32x32_fill_box_center_3.png><link rel=apple-touch-icon sizes=180x180 href=https://b.hui.ke/icon_hub7ca0b5404c6d576559b2bd22c64b0e5_2009_180x180_fill_box_center_3.png><meta name=description content="  单项选择题和程序设计考试题"><script type=application/ld+json>{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Docs","item":"https://b.hui.ke/docs/"},{"@type":"ListItem","position":2,"name":"Python","item":"https://b.hui.ke/docs/python/"},{"@type":"ListItem","position":3,"name":"【第8周程序】程序设计方法学","item":"https://b.hui.ke/docs/python/18/"}]}</script><script type=application/ld+json>{"@context":"https://schema.org","@type":"Article","mainEntityOfPage":{"@type":"WebPage","@id":"https://b.hui.ke/docs/python/18/"},"headline":"【第8周程序】程序设计方法学 | Python | Hui.Ke - Blog","datePublished":"2022-05-03T18:52:28+08:00","dateModified":"2022-05-03T18:52:28+08:00","wordCount":1632,"author":{"@type":"Person","name":"Hui.Ke"},"publisher":{"@type":"Person","name":"Hui.Ke","logo":{"@type":"ImageObject","url":"https://b.hui.ke/icon.png"}},"description":"\u003cp\u003e  单项选择题和程序设计考试题\u003c\/p\u003e"}</script><meta property="og:title" content="【第8周程序】程序设计方法学 | Python | Hui.Ke - Blog"><meta property="og:type" content="article"><meta property="og:image" content="https://b.hui.ke/icon.png"><meta property="og:url" content="https://b.hui.ke/docs/python/18/"><meta property="og:description" content="  单项选择题和程序设计考试题"><meta property="og:site_name" content="Hui.Ke - Blog"><meta property="article:published_time" content="2022-05-03T18:52:28+08:00"><meta property="article:modified_time" content="2022-05-03T18:52:28+08:00"><meta property="article:section" content="docs"><meta property="article:tag" content="Program"><meta property="og:see_also" content="https://b.hui.ke/docs/python/20/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/10/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/19/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/9/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/8/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/17/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/7/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/16/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/6/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/15/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/5/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/14/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/4/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/13/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/3/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/12/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/2/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/11/"><meta property="og:see_also" content="https://b.hui.ke/docs/python/1/"><script>!function(e){"use strict";!function(){var i,s=window,o=document,a=e,c="".concat("https:"===o.location.protocol?"https://":"http://","sdk.51.la/js-sdk-pro.min.js"),n=o.createElement("script"),r=o.getElementsByTagName("script")[0];n.type="text/javascript",n.setAttribute("charset","UTF-8"),n.async=!0,n.src=c,n.id="LA_COLLECT",a.d=n,i=function(){s.LA.ids.push(a)},s.LA?s.LA.ids&&i():(s.LA=e,s.LA.ids=[],i()),r.parentNode.insertBefore(n,r)}()}({id:"Jgb8aUbG5e3rqhrs",ck:"Jgb8aUbG5e3rqhrs",autoTrack:!0,hashMode:!0})</script><body class="flex min-h-screen flex-col"><header class="min-h-16 pl-scrollbar bg-secondary-bg fixed z-50 flex w-full items-center shadow-sm"><div class="mx-auto w-full max-w-screen-xl"><script>let storageColorScheme=localStorage.getItem("lightDarkMode");((storageColorScheme=="Auto"||storageColorScheme==null)&&window.matchMedia("(prefers-color-scheme: dark)").matches||storageColorScheme=="Dark")&&document.getElementsByTagName("html")[0].classList.add("dark")</script><nav class="flex items-center justify-between flex-wrap px-4 py-4 md:py-0"><a href=/ class="me-6 text-primary-text text-xl font-bold">Hui.Ke - Blog</a>
<button id=navbar-btn class="md:hidden flex items-center px-3 py-2" aria-label="Open Navbar">
<i class="fas fa-bars"></i></button><div id=target class="hidden block md:flex md:grow md:justify-between md:items-center w-full md:w-auto text-primary-text z-20"><div class="md:flex md:h-16 text-sm md:grow pb-4 md:pb-0 border-b md:border-b-0"><a href=/posts/ class="block mt-4 md:inline-block md:mt-0 md:h-(16-4px) md:leading-(16-4px) box-border md:border-t-2 md:border-b-2 border-transparent me-4">Posts</a>
<a href=/docs/ class="block mt-4 md:inline-block md:mt-0 md:h-(16-4px) md:leading-(16-4px) box-border md:border-t-2 md:border-b-2 selected-menu-item me-4">Docs</a>
<a href=/categories/ class="block mt-4 md:inline-block md:mt-0 md:h-(16-4px) md:leading-(16-4px) box-border md:border-t-2 md:border-b-2 border-transparent me-4">Categories</a>
<a href=/series/ class="block mt-4 md:inline-block md:mt-0 md:h-(16-4px) md:leading-(16-4px) box-border md:border-t-2 md:border-b-2 border-transparent me-4">Series</a>
<a href=/tags/ class="block mt-4 md:inline-block md:mt-0 md:h-(16-4px) md:leading-(16-4px) box-border md:border-t-2 md:border-b-2 border-transparent me-4">Tags</a>
<a href=/love/ class="block mt-4 md:inline-block md:mt-0 md:h-(16-4px) md:leading-(16-4px) box-border md:border-t-2 md:border-b-2 border-transparent me-4">Love</a>
<a href=/about/ class="block mt-4 md:inline-block md:mt-0 md:h-(16-4px) md:leading-(16-4px) box-border md:border-t-2 md:border-b-2 border-transparent me-4">About</a></div><div class=flex><div class="relative pt-4 md:pt-0"><div class="cursor-pointer hover:text-eureka" id=lightDarkMode><i class="fas fa-adjust"></i></div><div class="fixed hidden inset-0 opacity-0 h-full w-full cursor-default z-30" id=is-open></div><div class="absolute flex flex-col start-0 md:start-auto end-auto md:end-0 hidden bg-secondary-bg w-48 rounded py-2 border border-tertiary-bg cursor-pointer z-40" id=lightDarkOptions><span class="px-4 py-1 hover:text-eureka" name=Light>Light</span>
<span class="px-4 py-1 hover:text-eureka" name=Dark>Dark</span>
<span class="px-4 py-1 hover:text-eureka" name=Auto>Auto</span></div></div></div></div><div class="fixed hidden inset-0 opacity-0 h-full w-full cursor-default z-0" id=is-open-mobile></div></nav><script>let element=document.getElementById("lightDarkMode");storageColorScheme==null||storageColorScheme=="Auto"?document.addEventListener("DOMContentLoaded",()=>{window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",switchDarkMode)}):storageColorScheme=="Light"?(element.firstElementChild.classList.remove("fa-adjust"),element.firstElementChild.setAttribute("data-icon","sun"),element.firstElementChild.classList.add("fa-sun")):storageColorScheme=="Dark"&&(element.firstElementChild.classList.remove("fa-adjust"),element.firstElementChild.setAttribute("data-icon","moon"),element.firstElementChild.classList.add("fa-moon")),document.addEventListener("DOMContentLoaded",()=>{getcolorscheme(),switchBurger()})</script></div></header><main class="grow pt-16"><div class=pl-scrollbar><div class="mx-auto w-full max-w-screen-xl lg:px-4 xl:px-8"><div class=lg:pt-12><div class="flex flex-col md:flex-row bg-secondary-bg rounded"><div class="md:w-1/4 lg:w-1/5 border-e"><div class="sticky top-16 pt-6"><div id=sidebar-title class="md:hidden mx-4 px-2 pt-4 pb-2 md:border-b text-tertiary-text md:text-primary-text"><span class=font-semibold>Table of Contents</span>
<i class='fas fa-caret-right ms-1'></i></div><div id=sidebar-toc class="hidden md:block overflow-y-auto mx-6 md:mx-0 pe-6 pt-2 md:max-h-doc-sidebar bg-primary-bg md:bg-transparent"><div class="flex flex-wrap ms-4 -me-2 p-2 bg-secondary-bg md:bg-primary-bg rounded"><a class=hover:text-eureka href=https://b.hui.ke/docs/python/>Python</a></div><ul class=ps-6><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/20/>期末测验</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/10/>【第9+周笔记】全课程总结与学习展望</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/19/>【第9周程序】计算生态纵览</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/9/>【第9周笔记】计算生态纵览</a></div></li><li class=py-2><div><a class="text-eureka hover:text-eureka" href=https://b.hui.ke/docs/python/18/>【第8周程序】程序设计方法学</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/8/>【第8周笔记】程序设计方法学</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/17/>【第7周程序】文件和数据格式化</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/7/>【第7周笔记】文件和数据格式化</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/16/>【第6周程序】组合数据类型</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/6/>【第6周笔记】组合数据类型</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/15/>【第5周程序】函数和代码复用</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/5/>【第5周笔记】函数和代码复用</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/14/>【第4周程序】程序的控制结构</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/4/>【第4周笔记】程序的控制结构</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/13/>【第3周程序】基本数据类型</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/3/>【第3周笔记】基本数据类型</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/12/>【第2周程序】Python 基本图形绘制</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/2/>【第2周笔记】Python 基本图形绘制</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/11/>【第1周程序】Python 基本语法元素</a></div></li><li class=py-2><div><a class=hover:text-eureka href=https://b.hui.ke/docs/python/1/>【第1周笔记】Python 基本语法元素</a></div></li></ul></div></div></div><div class="w-full md:w-3/4 lg:w-4/5 pb-8 pt-2 md:pt-8"><div class=flex><div class="w-full lg:w-3/4 px-6"><article class=prose><h1 class=mb-4>【第8周程序】程序设计方法学</h1><div class="text-tertiary-text not-prose mt-2 flex flex-row flex-wrap items-center"><div class="me-6 my-2"><i class="fas fa-calendar me-1"></i>
<span>2022-05-03</span></div><div class="me-6 my-2"><i class="fa-solid fa-pen-to-square me-1"></i>
<span>2022-05-03</span></div><div class="me-6 my-2"><i class="fas fa-clock me-1"></i>
<span>4 min read</span></div><div class="me-6 my-2"><i class="fas fa-folder me-1"></i>
<a href=https://b.hui.ke/categories/it/ class=hover:text-eureka>IT</a></div><div class="me-6 my-2"><i class="fas fa-th-list me-1"></i>
<a href=https://b.hui.ke/series/python/ class=hover:text-eureka>Python</a></div><div class="me-6 my-2"><i class="fa-solid fa-eye me-1"></i>
<span id=busuanzi_value_page_pv><i class="fa fa-spinner fa-spin"></i></span> Hits</div></div><p>  单项选择题和程序设计考试题</p><h2 id=单项选择题>单项选择题</h2><ol><li><p>自顶向下设计主要由下列哪个语法元素实现？C</p><p>A. 对象</p><p>B. 过程</p><p>C. 函数</p><p>D. 循环结构</p></li></ol><ul><li>函数是自顶向下设计的关键元素，通过定义函数及其参数逐层开展程序设计。</li></ul><ol start=2><li><p>关于 os.path 子库，以下选项中用来计算相对路径的函数是：A</p><p>A. os.path.relpath(path)</p><p>B. os.path.abspath(path)</p><p>C. os.path.basename(path)</p><p>D. os.path.normpath(path)</p></li></ol><ul><li>顾名思义：os.path.relpath(path) 是 relative path 处理函数。</li></ul><ol start=3><li><p>以下选项对计算思维本质描述正确的是：B</p><p>A. 抽象和执行</p><p>B. 抽象和自动化</p><p>C. 描述和执行</p><p>D. 计算和思维</p></li></ol><ul><li><p>计算思维的本质是：抽象和自动化。</p></li><li><p>抽象一个运算过程，以能够按步骤描述为目标；并利用计算机运算的高速特性自动化执行。</p></li></ul><ol start=4><li><p>关于 os 库，以下选项中可以启动进程执行程序的函数是：B</p><p>A. os.process()</p><p>B. os.system()</p><p>C. os.start()</p><p>D. os.run()</p></li></ol><ul><li>除了 os.system()，选项其他函数都不存在。</li></ul><ol start=5><li><p>关于软件产品和程序的区别，以下描述正确的是：C</p><p>A. 软件产品 = 程序功能 + 速度优化</p><p>B. 软件程序就是软件产品</p><p>C. 软件产品 = 程序功能 + 用户体验</p><p>D. 从程序功能到软件产品的产品化代价很小</p></li></ol><ul><li>产品不仅需要功能，更需要更好的用户体验。往往，产品都需要综合考虑技术功能和人文设计，这源于产品的商业特性。即，商业竞争要求产品不能只关心技术功能，更要关心用户易用和喜好需求。</li></ul><ol start=6><li><p>关于 Python 的 os 库，以下选项描述正确的是：B</p><p>A. os 库提供了几十个函数，功能比较有限</p><p>B. os 库提供了路径操作、进程管理等若干类功能</p><p>C. os 库是一个第三方库，需要安装后使用</p><p>D. os 库仅适用于 Windows 平台</p></li></ol><ul><li>os 库是 Python 重要的标准库之一，提供了几百个函数功能，覆盖与操作系统、文件操作等相关的众多功能。os 库适合所有操作系统。</li></ul><ol start=7><li><p>以下选项关于计算生态描述错误的是：D</p><p>A. 计算生态主要以开源项目为组织形式</p><p>B. 计算生态存在竞争发展、相互依存和迅速更迭的特点</p><p>C. 计算生态类似自然生态，不受单一组织或人物的控制，形成了技术演化路径</p><p>D. 高质量计算生态需要顶层设计的参与才能保障</p></li></ol><ul><li>计算生态以竞争发展、相互依存和迅速更迭为特点，在开源项目间不存在顶层设计，以类自然界"适者生存"的方式形成技术演进路径。</li></ul><ol start=8><li><p>关于 Python 第三方库安装方法，以下选项描述错误的是：A</p><p>A. 联系第三方库作者索要安装文件</p><p>B. 访问 UCI 网站下载安装文件</p><p>C. 使用集成安装工具</p><p>D. 使用 pip 命令</p></li></ol><ul><li>请不要联系作者索要第三方库，这不是获取第三方库的合理模式。</li></ul><ol start=9><li><p>关于用户体验，以下选项描述正确的是：A</p><p>A. 编程只是手段，程序最终为人类服务，用户体验很重要</p><p>B. 用户体验是客观的，完全可以靠技术来实现</p><p>C. 好产品不一定有好的用户体验，关键在于功能创意</p><p>D. 用户体验不重要，只要有程序功能即可</p></li></ol><ul><li>一个提醒进度的进度条、一个永不抛出异常的程序、一个快速的响应、一个漂亮的图标、一个合适尺寸的界面等都是用户体验的组成部分。总的来说，用户体验是一切能够提升程序用户感受的组成。</li></ul><ol start=10><li><p>关于计算思维，以下选项描述正确的是：C</p><p>A. 计算思维从古至今一直存在</p><p>B. 计算思维关于设计和构造，可以脱离计算机而存在</p><p>C. 计算思维是基于计算机的思维模式</p><p>D. 计算思维是逻辑思维的演进</p></li></ol><ul><li>计算思维是基于计算机的思维模式，计算机出现之前，由于没有快速计算装置，计算所反映的思维模式主要是数学思维，即通过公式来求解问题。当快速计算装置出现后，计算思维才真正形成。</li></ul><h2 id=英文字符的鲁棒输入>英文字符的鲁棒输入</h2><p>获得用户的任何可能输入，将其中的英文字符进行打印输出，程序不出现错误。</p><h3 id=参考答案>参考答案</h3><pre><code class=language-python>alpha = []
for i in range(26):
    alpha.append(chr(ord('a') + i))
    alpha.append(chr(ord('A') + i))
s = input()
for c in s:
    if c in alpha:
        print(c, end=&quot;&quot;)
</code></pre><h3 id=答案解析>答案解析</h3><p>注意：这里采用遍历字符的方式实现，通过约束字母表达到鲁棒效果。</p><h3 id=最优解>最优解</h3><pre><code class=language-python>for ch in input():
    if ord('a') &lt;= ord(ch) &lt;= ord('z') or ord('A')&lt;=ord(ch)&lt;=ord('Z'):
        print(ch,end='')
</code></pre><h2 id=数字的鲁棒输入>数字的鲁棒输入</h2><p>获得用户输入的一个数字，可能是浮点数或复数，如果是整数仅接收十进制形式，且只能是数字。对输入数字进行平方运算，输出结果。</p><p>要求：</p><ol><li>无论用户输入何种内容，程序无错误；</li><li>如果输入有误，请输出"输入有误"。</li></ol><h3 id=参考答案-1>参考答案</h3><pre><code class=language-python>s = input()
try:
    if complex(s) == complex(eval(s)):
        print(eval(s)**2)
except:
    print(&quot;输入有误&quot;)
</code></pre><h3 id=答案解析-1>答案解析</h3><p>complex() 和 complex(eval()) 之间的比较将能够排除非数字类型的输入。</p><p>注意：不能直接使用 eval()，否则，用户可以通过输入表达式（如100**2）输入数字，与要求不同（在实际应用中带来安全隐患）。</p></article><div class=my-4><a href=https://b.hui.ke/tags/program/ class="inline-block bg-tertiary-bg text-sm rounded px-3 py-1 my-1 me-2 hover:text-eureka">#Program</a></div><div class=py-2><div class="my-8 flex flex-col items-center md:flex-row"><a href=https://b.hui.ke/authors/hui.ke/ class="md:me-4 text-primary-text h-24 w-24"><img src=https://b.hui.ke/bagua.webp class="bg-primary-bg w-full rounded-full" alt=Avatar></a><div class="mt-4 w-full md:mt-0 md:w-auto"><a href=https://b.hui.ke/authors/hui.ke/ class="mb-2 block border-b pb-1 text-lg font-bold"><h3>Hui.Ke</h3></a><span class="block pb-2">❤ Cyber Security | Safety is a priority.</span>
<a href=mailto:3199731997@qq.com class=me-2><i class="fas fa-envelope"></i></a>
<a href="https://wpa.qq.com/msgrd?v=3&uin=3199731997" class=me-2><i class="fab fa-qq"></i></a>
<a href=/images/aixinxianquan.webp class=me-2><i class="fab fa-weixin"></i></a></div></div></div><div class="-mx-2 mt-4 flex flex-col border-t px-2 pt-4 md:flex-row md:justify-between"><div><span class="text-primary-text block font-bold">Previous</span>
<a href=https://b.hui.ke/docs/python/9/ class=block>【第9周笔记】计算生态纵览</a></div><div class="mt-4 md:mt-0 md:text-right"><span class="text-primary-text block font-bold">Next</span>
<a href=https://b.hui.ke/docs/python/8/ class=block>【第8周笔记】程序设计方法学</a></div></div><div id=valine-comments class=mt-4></div><script defer src=https://cdn.jsdelivr.net/npm/valine@1.4.16/dist/Valine.min.js integrity=sha384-e0+DNUCJo75aOAzHQbFWYBCM9/S4f0BhRJXvEgbE3mMS85RM20MSSGStHuNdY2QK crossorigin></script>
<script>document.addEventListener("DOMContentLoaded",function(){new Valine({el:"#valine-comments",appId:"BQnVqWIiq78AdqwyhvBVAa3y-MdYXbMMI",appKey:"RKg5By312YjM8rU6WkkfK9IN",recordIP:"true",serverURLs:"https://l.hui.ke",visitor:"true"})})</script></div><div class="hidden lg:block lg:w-1/4"><div class="bg-secondary-bg
prose sticky top-16 z-10 hidden px-6 py-4 lg:block"><h3>On This Page</h3></div><div class="sticky-toc
border-s
hidden px-6 pb-6 lg:block"><nav id=TableOfContents><ul><li><a href=#单项选择题>单项选择题</a></li><li><a href=#英文字符的鲁棒输入>英文字符的鲁棒输入</a><ul><li><a href=#参考答案>参考答案</a></li><li><a href=#答案解析>答案解析</a></li><li><a href=#最优解>最优解</a></li></ul></li><li><a href=#数字的鲁棒输入>数字的鲁棒输入</a><ul><li><a href=#参考答案-1>参考答案</a></li><li><a href=#答案解析-1>答案解析</a></li></ul></li></ul></nav></div><script>window.addEventListener("DOMContentLoaded",()=>{enableStickyToc()})</script></div></div></div></div></div><script>document.addEventListener("DOMContentLoaded",()=>{hljs.highlightAll(),changeSidebarHeight(),switchDocToc()})</script></div></div></main><footer class=pl-scrollbar><div class="mx-auto w-full max-w-screen-xl"><div class="text-center p-6 pin-b"><script async src=/js/click.js></script><div id=poem_ip></div><script type=text/javascript>jinrishici.load(function(e){tags.innerHTML=e.data.matchTags})</script><div><span id=timeDate>载入年天数...</span><span id=times>载入时分秒...</span>
<script async src=/js/duration.js></script></div><a href=https://www.foreverblog.cn/go.html target=_blank><img src=https://img.foreverblog.cn/wormhole_4_tp.gif alt style=display:inline-block;width:auto;height:32px title=穿梭虫洞-随机访问十年之约友链博客></a><p class="text-sm text-tertiary-text"><script async src=//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js></script>本站总访问量 <span id=busuanzi_value_site_pv></span> 次
&#183; 您是本站的第 <span id=busuanzi_value_site_uv></span> 个小伙伴</p><script async src=/js/tab.js></script></div></div></footer></body></html>